﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuanLyBanHang.QuerySQL;
using System.Data;
using System.Windows.Forms;
using QuanLyBanHang.DataConnection;
namespace QuanLyBanHang.QuerySQL
{
    class ClassLSP
    {
        Connect conn = new Connect();
        public DataTable ShowLSP()
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from LOAISP";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        public void ThemLSP(string maloai, string tenloai)
        {
            try
            {
                string sql = "insert into LOAISP values('" + maloai + "',N'" + tenloai + "')";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Thêm thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        public void SuaLSP(string maloai, string tenloai)
        {
            try
            {
                string sql = "update LOAISP set TENLOAI = N'"+tenloai+"' where MALOAI = '"+maloai+"' ";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Sửa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        public void XoaLSP(string maloai)
        {
            try
            {
                string sql = "delete LOAISP where MALOAI = '" + maloai + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Xóa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
    }
}
